package cn.hackcloud.mutithread.mutilthread.lock;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class MyService {
	private Lock lock = new ReentrantLock();

	public void test() {
		lock.lock();
		try {
			for (int i = 0; i < 5; i++) {
				System.out.println("线程" + Thread.currentThread().getName() + "-" + (i + 1));
			}
		} finally {
			lock.unlock();
		}
	}

	public static void main(String[] args) {
		MyService myService = new MyService();
		MyThread t1 = new MyThread(myService);
		MyThread t2 = new MyThread(myService);
		MyThread t3 = new MyThread(myService);
		MyThread t4 = new MyThread(myService);
		t1.start();
		t2.start();
		t3.start();
		t4.start();

	}
}
